//
//  AppDelegate+RNOLBasicSettings.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/9.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "AppDelegate+RNOLBasicSettings.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
//腾讯开放平台（对应QQ和QQ空间）SDK头文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
//微信SDK头文件
#import "WXApi.h"
//新浪微博SDK头文件<
#import "WeiboSDK.h"
//新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加”-ObjC”

/// 友盟统计
#import <UMCommon/UMCommon.h>


@implementation AppDelegate (RNOLBasicSettings)

+ (void)load{
    [super load];
    static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(rnolBS_applicationDidFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];
        });
}

#pragma mark- 接收通知
+ (void)rnolBS_applicationDidFinishLaunching:(NSNotification *)note{
    [self rnol_serverHostSetting];
    [self rnol_UIBasicSetting];
    [self rnol_startUMSocialStatistics];
    [self rnol_shareConfigSetting];
}

#pragma mark- 域名的配置
+ (void)rnol_serverHostSetting{
    // 默认的域名配置
    [RNOLServerHostManager defaultServerHostConfiguration];
}

#pragma mark- 一些UI的全局设置
+ (void)rnol_UIBasicSetting{
    SVProgressHUD *hud =[SVProgressHUD appearance];
    [hud setDefaultStyle:SVProgressHUDStyleDark];
    [hud setDefaultMaskType:SVProgressHUDMaskTypeGradient];
    [hud setDefaultAnimationType: SVProgressHUDAnimationTypeFlat];
}

#pragma mark- 友盟统计
+ (void)rnol_startUMSocialStatistics{
#ifdef DEBUG
    //Debug
#else
    //发布后
    [UMConfigure setLogEnabled:YES];
    [UMConfigure setEncryptEnabled:YES];
    [UMConfigure initWithAppkey:kUMSocialKey channel: nil];
#endif
    

}

#pragma mark- 分享
+ (void)rnol_shareConfigSetting{
    /**初始化ShareSDK应用
     
     @param activePlatforms
     使用的分享平台集合
     @param importHandler (onImport)
     导入回调处理，当某个平台的功能需要依赖原平台提供的SDK支持时，需要在此方法中对原平台SDK进行导入操作
     @param configurationHandler (onConfiguration)
     配置回调处理，在此方法中根据设置的platformType来填充应用配置信息
     */
    [ShareSDK registerActivePlatforms:@[
                                        @(SSDKPlatformTypeSinaWeibo),
                                        @(SSDKPlatformTypeMail),
                                        @(SSDKPlatformTypeSMS),
                                        @(SSDKPlatformTypeCopy),
                                        @(SSDKPlatformTypeWechat),
                                        @(SSDKPlatformTypeQQ)
                                        ]
                             onImport:^(SSDKPlatformType platformType)
     {
         switch (platformType)
         {
             case SSDKPlatformTypeWechat:
                 [ShareSDKConnector connectWeChat:[WXApi class]];
                 break;
             case SSDKPlatformTypeQQ:
                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                 break;
             case SSDKPlatformTypeSinaWeibo:
                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];
                 break;
             default:
                 break;
         }
     }
        onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
     {
         switch (platformType)
         {
             case SSDKPlatformTypeSinaWeibo:
                 //设置新浪微博应用信息,其中authType设置为使用SSO＋Web形式授权
                 [appInfo SSDKSetupSinaWeiboByAppKey: kSinaAppID
                                           appSecret: kSinaAppSecret
                                         redirectUri: kSinaRedirectUri
                                            authType: SSDKAuthTypeSSO];
                 break;
             case SSDKPlatformTypeWechat:
                 [appInfo SSDKSetupWeChatByAppId: kWeiXinAppKey
                                       appSecret: kWeiXinSecret];
                 break;
             case SSDKPlatformTypeQQ:
                 [appInfo SSDKSetupQQByAppId: kQQAppID
                                      appKey: kQQAppKey
                                    authType: SSDKAuthTypeSSO];
                 break;
             default:
                 break;
         }
     }];
    
}



@end
